﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GONES.IBLL;
using GONES.Tools.Common;
using GONES.Model;
using System.Text;

public partial class Console_System_Dic_DicTreeList : CPage
{

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public string GetDicTreeList(string ParentId)
    {
        StringBuilder treestr = new StringBuilder();
        IList<DataFilter> dataFilters = new List<DataFilter>();
        var dicManager = AppContext.GetObject("S_DicManager") as IS_DicManager;
        DataFilter df = new DataFilter() { Type = "string", Value = ParentId, Field = "Parentid" };
        df.Comparison = "eq";
        dataFilters.Add(df);
        IList<S_Dic> diclist = dicManager.List(dataFilters);
        S_Dic dic = new S_Dic();
        for (int i = 0; i < diclist.Count; i++)
        {
            dic = (S_Dic)diclist[i]; //target=\"dialog\" rel=\"{1}\"
           treestr.Append(string.Format("<li><a href=\"#\"  tname=\"{0}\" tvalue=\"{1}\" onclick=\"setdicid('{2}');return false;\" >{3} </a>",
                                   dic.Title, dic.ID, dic.ID, dic.Title));
           GetChildDicTreeList(dic.ID, ref treestr);
        }
       treestr.Append("</li>");
        return treestr.ToString();
    }

    public void GetChildDicTreeList(string parentId,ref StringBuilder treestr )
    {
        IList<DataFilter> dataFilters = new List<DataFilter>();
        var dicManager = AppContext.GetObject("S_DicManager") as IS_DicManager;
        DataFilter df = new DataFilter() { Type = "string", Value = parentId, Field = "Parentid" };
        df.Comparison = "eq";
        dataFilters.Add(df);
        IList<S_Dic> diclist = dicManager.List(dataFilters);
        S_Dic dic = new S_Dic();
        treestr.Append("<ul>");
        for (int i = 0; i < diclist.Count; i++)
        {
            dic = (S_Dic)diclist[i]; //target=\"dialog\" rel=\"{1}\"
            if (dicManager.GetDicCountByParentId(dic.ID) == 0)
            {
                treestr.Append(string.Format("<li><a href=\"#\"  tname=\"{0}\" tvalue=\"{1}\" onclick=\"setorgid('{2}');return false;\" >{3} </a></li>",
                                         dic.Title, dic.ID, dic.ID, dic.Title));
            }
            else
            {
                treestr.Append(string.Format("<li><a href=\"#\"  tname=\"{0}\" tvalue=\"{1}\" onclick=\"setorgid('{2}');return false;\" >{3} </a>",
                                         dic.Title, dic.ID, dic.ID, dic.Title));
                GetChildDicTreeList(dic.ID, ref treestr);
            }
        }
        treestr.Append("</ul>");
    }


}